<?php require_once('Connections/locamedicadmin.php'); ?>

<?php include('userValidation.php'); ?>

<?php require_once('functions.php'); ?>

<?php
$currentPage = $_SERVER["PHP_SELF"];

$maxRows_client = 20;
$pageNum_client = 0;

if (isset($_GET['pageNum_client'])) {
  $pageNum_client = $_GET['pageNum_client'];
}
$startRow_client = $pageNum_client * $maxRows_client;

mysql_select_db($database_locamedicadmin, $locamedicadmin);
$query_client = "SELECT * from csre_client where deleted = 0";


$order = "";
$orderby = "";

if (isset($_POST['order']) && isset($_POST['orderby'])) {

	$order = $_POST['order'];
	$orderby = $_POST['orderby'];
	
	$query_client = $query_client . " order by " . $order . " " . $orderby;

}
$query_limit_client = sprintf("%s LIMIT %d, %d", $query_client, $startRow_client, $maxRows_client);
$client = mysql_query($query_limit_client, $locamedicadmin) or die(mysql_error());
$row_client = mysql_fetch_assoc($client);





if (isset($_GET['totalRows_client'])) {
  $totalRows_client = $_GET['totalRows_client'];
} else {
  $all_client = mysql_query($query_client);
  $totalRows_client = mysql_num_rows($all_client);
}
$totalPages_client = ceil($totalRows_client/$maxRows_client)-1;

$queryString_client = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_client") == false && 
        stristr($param, "totalRows_client") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_client = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_client = sprintf("&totalRows_client=%d%s", $totalRows_client, $queryString_client);
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Locamedic CSRE Admin</title>
<link href="locamedicadmin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="page">

	<?php include('sidebar.php'); ?>
	
	<!-- end sidebar -->
	<div id="content">
		<div align="center"><img src="images/page_image_5.jpg" alt="" /></div>
	  <div class="boxed">
		<h1 class="title2">Client List</h1>
		<br />

			<form action="client_list.php" method="post">
				<table cellpadding="5" class="text">
					<tr>
						<td>
							Trier par
						</td>
						<td>&nbsp;
							
						</td>
					</tr>
					<tr>
						<td width="100">
							<select name="order">
								<option <?php if ($order == 'name') { echo "selected='selected' "; } ?> value="name">Nom</option>
								<option <?php if ($order == 'locamedic_client_number') { echo "selected='selected' "; } ?> value="locamedic_client_number">
									Locamedic#
								</option>
								<option <?php if ($order == 'medipoints') { echo "selected='selected' "; } ?> value="medipoints">Medipoints</option>
							</select>
						</td>
						<td>
							<select name="orderby">
								<option <?php if ($orderby == 'asc') { echo "selected='selected' "; } ?> value="asc">&uarr;</option>
								<option <?php if ($orderby == 'desc') { echo "selected='selected' "; } ?>value="desc">&darr;</option>
							</select>
						</td>
					</tr>
					<tr>
						<td colspan="2">												
							<div class="botonera">
								<input type="submit" value="Trier" />
							</div>
						</td>
					</tr>
				</table>
			</form>

		<br />

		<?php if ($totalRows_client > 0) { ?>		
		
		<table cellpadding="5" cellspacing="0">
		   <thead>
			<td>Name</td>
			<td>Enabled</td>
			<td>New</td>
			<td># Locamedic</td>
			<td>Medipoints</td>
			<td width="5%"></td>
			<td width="5%"></td>
		  </thead>
		  <?php do { ?>
			<tr>
			  <td><?php echo $row_client['name']; ?></td>
			  <td><?php if ($row_client['enabled']) { echo "OUI"; } else { echo "NON"; } ?></td>
			  <td><?php if ($row_client['pending_new']) { echo "OUI"; } else { echo "NON"; } ?></td>
			  <td><?php echo $row_client['locamedic_client_number']; ?></td>
			  <td><?php echo $row_client['medipoints']; ?></td>
			  <td>
				<a href="client_edit.php?client_id=<?php echo $row_client['client_id']; ?>">
					<img src="images/1307905892_desktop.png" alt="Modifier" border="0" />
				</a>
			  </td>
			  <td>
				<a href="client_delete.php?client_id=<?php echo $row_client['client_id']; ?>"
					onclick="return confirm('Etes-vous sûr de vouloir supprimer ce registre?');">
					<img src="images/1307905898_edit-trash.png" alt="Supprimer" border="0" />
				</a>
			  </td>
			</tr>
			<?php } while ($row_client = mysql_fetch_assoc($client)); ?>
		</table>
		<table>
			<tr>
				<td align="center">
					Rows <?php echo ($startRow_client + 1) ?> to <?php echo min($startRow_client + $maxRows_client, $totalRows_client) ?> of <?php echo $totalRows_client ?>
				</td>
			</tr>
		</table>
		       

		
		<table border="0" width="50%" align="center">
          <tr>
            <td width="23%" align="center"><?php if ($pageNum_client > 0) { // Show if not first page ?>
                  <a href="<?php printf("%s?pageNum_client=%d%s", $currentPage, 0, $queryString_client); ?>"><img src="images/resultset_first.png" border=0></a>
                  <?php } // Show if not first page ?>
            </td>
            <td width="31%" align="center"><?php if ($pageNum_client > 0) { // Show if not first page ?>
                  <a href="<?php printf("%s?pageNum_client=%d%s", $currentPage, max(0, $pageNum_client - 1), $queryString_client); ?>"><img src="images/resultset_previous.png" border=0></a>
                  <?php } // Show if not first page ?>
            </td>
            <td width="23%" align="center"><?php if ($pageNum_client < $totalPages_client) { // Show if not last page ?>
                  <a href="<?php printf("%s?pageNum_client=%d%s", $currentPage, min($totalPages_client, $pageNum_client + 1), $queryString_client); ?>"><img src="images/resultset_next.png" border=0></a>
                  <?php } // Show if not last page ?>
            </td>
            <td width="23%" align="center"><?php if ($pageNum_client < $totalPages_client) { // Show if not last page ?>
                  <a href="<?php printf("%s?pageNum_client=%d%s", $currentPage, $totalPages_client, $queryString_client); ?>"><img src="images/resultset_last.png" border=0></a>
                  <?php } // Show if not last page ?>
            </td>
          </tr>
        </table>
		<?php } else { ?>
		<table>
			<tr>
				<td>No client found</td>
			</tr>
		</table>
		<?php } ?>
        <div class="botonera">
			<input type="button" onclick="window.location='client_add.php';" value="Add client" />
		</div>
		
	  </div>
  </div>
	<!-- end content -->
	<div style="clear: both;">&nbsp;</div>
</div>
<!-- end page -->

<?php include('footer.php'); ?>

</body>
</html>
<?php
mysql_free_result($client);
?>